package com.wty.design.structural.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author wangtengyu
 * @Create 2018-09-19-15:21
 * 课程目录类
 */
public class CourseCatalog extends CatalogComponent {
    private String name;
    private Integer level;
    private List<CatalogComponent> items=new ArrayList<CatalogComponent>();

    public CourseCatalog(String name, Integer level) {
        this.name = name;
        this.level = level;
    }

    @Override
    public void add(CatalogComponent catalogComponent) {
        items.add(catalogComponent);
    }

    @Override
    public void remove(CatalogComponent catalogComponent) {
        items.remove(catalogComponent);
    }

    @Override
    public String getName(CatalogComponent catalogComponent) {
        return this.name;
    }

    @Override
    public void print() {
        System.out.println(this.name);
        for (CatalogComponent catalogComponent:items){
            if (this.level!=null){//是目录
                for (int i=0;i<this.level;i++){
                    System.out.print("   ");
                }
            }
            catalogComponent.print();
        }
    }
}
